#include <iostream>
#include <stack>
#include <string>

using namespace std;

class Solution {
public:
    string decodeString(string s) {
        stack<pair<int, string>> stack;
        int mul = 0;
        string ans;
        for (char& c : s) {
            if (c == '[') {
                stack.push({mul, ans});
                mul = 0;
                ans = "";
            } else if (c == ']') {
                pair<int, string>& top = stack.top();
                for (int i = 0; i < top.first; i++) {
                    top.second += ans;
                }
                ans = top.second;
                stack.pop();
            } else if (c >= '0' && c <= '9') {
                mul = mul * 10 + (c - '0');
            } else {
                ans += c;
            }
        }
        return ans;
    }
};

int main() {
    Solution solution;
    string output = solution.decodeString("3[a]2[bc]");
    cout << output << endl;
    return 0;
}
